package com.szholly.pro.watergas_server.ps.controller;


import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.szholly.pro.watergas_server.common.util.JsonUtil;
import com.szholly.pro.watergas_server.common.web.BaseController;
import com.szholly.pro.watergas_server.common.web.RequestUnit;
import com.szholly.pro.watergas_server.ps.service.QCBaseInfoManagementService;
import com.szholly.pro.watergas_server.ps.service.QCSummaryEvaluationService;
import com.szholly.data.general.RowBase;


@Controller   //质控汇总评价
@RequestMapping("/QCSummaryEvaluationController/*")
public class QCSummaryEvaluationController  extends BaseController { 
	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	
	@Autowired
	QCSummaryEvaluationService qcSummaryEvaluationService;
	@Autowired
	QCBaseInfoManagementService qcBaseInfoManagerService;

	/**
	 * 获取质控汇总评价信息
	 * @param resq
	 * @param res
	 * @throws Exception
	 */
	@RequestMapping(value="/getSummaryEvaluationDataList")
	public void getSummaryEvaluationDataList(HttpServletRequest resq, HttpServletResponse res) throws Exception{
		Map<String, String> parm=queryStationQueryParams();
		HashMap<String,Object> data=new HashMap<>();
		List<RowBase> SumEvaList;
		List<RowBase> SumEvaDetailList;
		//汇总评价
		if("-1".equals(parm.get("QCType")))
		{
			SumEvaList = qcSummaryEvaluationService.getSummaryEvaluationDataList(parm);
			data.put("SumEvaList", SumEvaList);
		}else{//单独质控
			SumEvaList = qcSummaryEvaluationService.getSingleQCSumEvaDataList(parm);
			SumEvaDetailList =qcSummaryEvaluationService.getSingleQCSumEvaDetailDataList(parm);
			data.put("SumEvaList", SumEvaList);
			data.put("SumEvaDetailList", SumEvaDetailList);
		}
		outString(JsonUtil.ConvertObjectToJson(data));
	}
	/**
	 * 质控汇总评价导出
	 * @param resq
	 * @param res
	 * @throws Exception
	 */
	@RequestMapping(value="SummaryEvaluationToExcel")
	public void SummaryEvaluationToExcel(HttpServletRequest resq, HttpServletResponse res) throws Exception{
		Map<String, String> parm=queryStationQueryParams();
		String qctypeID=parm.get("QCType");
		HashMap<String,Object> data=new HashMap<>();
		List<RowBase> SumEvaList;
		List<RowBase> SumEvaDetailList;
		
		//汇总评价
		if("-1".equals(parm.get("QCType")))
		{
			SumEvaList = qcSummaryEvaluationService.getSummaryEvaluationDataList(parm);
			data.put("SumEvaList", SumEvaList);
		}else{//单独质控
			SumEvaList = qcSummaryEvaluationService.getSingleQCSumEvaDataList(parm);
			SumEvaDetailList =qcSummaryEvaluationService.getSingleQCSumEvaDetailDataList(parm);			
			data.put("SumEvaList", SumEvaList);			
			data.put("SumEvaDetailList", SumEvaDetailList);			
			data.put("result", parm.get("result"));
		}
		//获取质控类型
		List<RowBase> MonitorList = qcBaseInfoManagerService.getMonitorTypeList(parm);
		data.put("MonitorList", MonitorList);
		data.put("startDate", parm.get("startDate"));
		if(qctypeID.equals("-1")){
			HtmlToExcel(data, "qc/SumEva.html", "汇总评价.xls");
		}else if(qctypeID.equals("0")){
			HtmlToExcel(data, "qc/SumEvaFB.html", "现场空白.xls");
		}else if(qctypeID.equals("5")){
			HtmlToExcel(data, "qc/SumEvaEB.html", "实验室空白.xls");
		}else if(qctypeID.equals("1")){
			HtmlToExcel(data, "qc/SumEvaFCP.html", "现场平行样(密码).xls");
		}else if(qctypeID.equals("2")){
			HtmlToExcel(data, "qc/SumEvaPLC.html", "实验室平行样(明码).xls");
		}else if(qctypeID.equals("7")){
			HtmlToExcel(data, "qc/SumEvaLCP.html", "实验室平行样(密码).xls");
		}else if(qctypeID.equals("3")){
			HtmlToExcel(data, "qc/SumEvaSR.html", "加标回收.xls");
		}else if(qctypeID.equals("4")){
			HtmlToExcel(data, "qc/SumEvaSS.html", "标样(质控样).xls");
		}		
	}
	/**
	 * 获取参数方法
	 * @return
	 */
	private Map<String,String> queryStationQueryParams() {
		Map<String,String> params = new HashMap<>();
		String MONITORINGTYPE=RequestUnit.getString("MONITORINGTYPE");
		String MonitorMethod=RequestUnit.getString("MonitorMethod");
		String CompanyCode=RequestUnit.getString("CompanyCode");
		String QCType=RequestUnit.getString("QCType");
		String MONITORPARAMCODE=RequestUnit.getParameter("MONITORPARAMCODE");
		String endDate=RequestUnit.getString("endDate");
		String startDate=RequestUnit.getString("startDate");
		params.put("MONITORINGTYPE", MONITORINGTYPE);
		params.put("MonitorMethod", MonitorMethod);
		params.put("CompanyCode", CompanyCode);
		params.put("QCType", QCType);
		params.put("MONITORPARAMCODE", MONITORPARAMCODE);
		params.put("endDate", endDate);
		params.put("startDate", startDate);
		return params;		
	}
}
